/*
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2023/8/16 14:30
@File     : redis.go
@Project  : web_scaff
@Desc     :
*/
package configs

import (
	"fmt"

	"go.uber.org/zap"

	"github.com/go-redis/redis"
)

type Redis struct {
	Db   int    `json:"db" mapstructure:"db"`
	Host string `json:"host" mapstructure:"host"`
	Port uint   `json:"port" mapstructure:"port"`
	Pwd  string `json:"pwd" mapstructure:"pwd"`
}

var client *redis.Client

func init() {
	client = redis.NewClient(&redis.Options{
		Addr:         fmt.Sprintf("%s:%d", Conf.Redis.Host, Conf.Redis.Port),
		Password:     Conf.Redis.Pwd,
		DB:           Conf.Redis.Db,
		PoolSize:     10,
		MinIdleConns: 3,
	})
	if _, err := client.Ping().Result(); err != nil {
		zap.L().Error("redis初始化失败", zap.Error(err))
		panic(fmt.Errorf("redis初始化失败：程序退出……"))
	}

}
func CloseRedis() {
	client.Close()
}
